<?php
/**
* phpCan - http://idc.anavallasuiza.com/
*
* phpCan is released under the GNU Affero GPL version 3
*
* More information at license.txt
*/

defined('ANS') or die();
?>

<header class="clear">
	<hgroup>
		<h1><?php __e('Data Base Update'); ?></h1>
	</hgroup>
</header>

<article>
<?php if ($queries): ?>
	<form action="<?php echo path(); ?>" method="post">
		<fieldset class="inline">
			<?php echo $Form->hidden('update-db', 'phpcan_action'); ?>

			<table class="list">
				<thead>
					<tr>
						<th class="actions"><?php __e('Select'); ?></th>
						<th><?php __e('Queries'); ?></th>
						<th><?php __e('Status'); ?></th>
					</tr>
				</thead>

				<tbody>
					<?php foreach ($queries as $query): ?>
					<?php $id_query = uniqid(); ?>

					<tr>
						<td class="actions"><?php
							if ($query['status'] != 'executed') {
								echo $Form->checkbox(array(
									'name' => 'selected['.$query['key'].']',
									'id' => $id_query
								));
							}
						?></td>

						<td><label for="<?php echo $id_query; ?>" class="inline-block"><?php echo $query['query']; ?></label></td>

						<td><?php
							switch ($query['status']) {
								case 'error':
									echo ad(__('This query was an error'), 'error');
									break;

								case 'executed':
									echo ad(__('This query was executed succesfully'), 'success');
									break;

								default:
									echo ad(__('This query was not executed yet'));
									break;
							}
						?></td>
					</tr>
					<?php endforeach; ?>
				</tbody>
			</table>

			<div class="actions">
				<?php
				echo $Html->a(array(
					'text' => __('Select all'),
					'id' => 'option-select-all',
					'class' => 'option',
				));
				echo $Html->a(array(
					'text' => __('Select none'),
					'id' => 'option-select-none',
					'class' => 'option'
				));
				echo $Html->a(array(
					'text' => __('Invert selection'),
					'id' => 'option-invert-selection',
					'class' => 'option'
				));
				echo $Html->a(array(
					'href' => path(),
					'text' => __('Reload'),
					'class' => 'option'
				));

				echo $Form->submit('Update database');
				?>
			</div>
		</fieldset>
	</form>

<?php else: ?>
	<?php echo ad(__('Database is updated')); ?>
<?php endif; ?>
</article>
